

cap file close Table
pause on 

local summstats_Egypt_only				$summstats_Egypt_only

local summstats_Tunisia_only			$summstats_Tunisia_only

local all_summstats_Egypt_only    		$`summstats_Egypt_only'

local all_summstats_Tunisia_only    	$`summstats_Tunisia_only'

local title								endline_1_summstats


* Produce descriptive statistics using Egypt endline 1 data 
				
	foreach outcome in `all_summstats_Egypt_only' {

	use  "Data/endline_1_egypt_fem.dta", clear 
			
			* All residents
			
				summ `outcome'
				
					local c_1_`outcome' : di%12.3f `r(mean)'
					local sd_1_`outcome' : di%12.3f `r(sd)'
					local n_1_`outcome' = `r(N)'
		
			* Treatment residents
				
				summ `outcome' if within==1
				
					local c_2_`outcome' : di%12.3f `r(mean)'
					local sd_2_`outcome' : di%12.3f `r(sd)'
					local n_2_`outcome' = `r(N)'
			
			* Partial control residents
				
				summ `outcome' if within==0
				
					local c_3_`outcome' : di%12.3f `r(mean)'
					local sd_3_`outcome' : di%12.3f `r(sd)'
					local n_3_`outcome' = `r(N)'

			* Pure control residents
				
				summ `outcome' if between==0
				
					local c_4_`outcome' : di%12.3f `r(mean)'
					local sd_4_`outcome' : di%12.3f `r(sd)'
					local n_4_`outcome' = `r(N)'
					
			* All community members
				
				summ `outcome' if infrastructure!=.
				
					local c_5_`outcome' : di%12.3f `r(mean)'
					local sd_5_`outcome' : di%12.3f `r(sd)'
					local n_5_`outcome' = `r(N)'

			* Treatment community members
				
				summ `outcome' if infrastructure==1
				
					local c_6_`outcome' : di%12.3f `r(mean)'
					local sd_6_`outcome' : di%12.3f `r(sd)'
					local n_6_`outcome' = `r(N)'

			* Control community members
				
				summ `outcome' if infrastructure==0
				
					local c_7_`outcome' : di%12.3f `r(mean)'
					local sd_7_`outcome' : di%12.3f `r(sd)'
					local n_7_`outcome' = `r(N)'
			
					
					
	}
				
	foreach outcome of local all_summstats_Egypt_only {
		
		 local l_`outcome' : variable label `outcome'
		
	}

				
			

	
* Produce descriptive statistics using Tunisia endline 1 data 

	foreach outcome in `all_summstats_Tunisia_only' {

	use  "Data/endline_1_tunisia_fem.dta", clear 
					
			* All residents
			
				summ `outcome'
				
					local c_8_`outcome' : di%12.3f `r(mean)'
					local sd_8_`outcome' : di%12.3f `r(sd)'
					local n_8_`outcome' = `r(N)'
		
			* Treatment residents
				
				summ `outcome' if within==1
				
					local c_9_`outcome' : di%12.3f `r(mean)'
					local sd_9_`outcome' : di%12.3f `r(sd)'
					local n_9_`outcome' = `r(N)'
			
			* Partial control residents
				
				summ `outcome' if within==0
				
					local c_10_`outcome' : di%12.3f `r(mean)'
					local sd_10_`outcome' : di%12.3f `r(sd)'
					local n_10_`outcome' = `r(N)'

			* Pure control residents
				
				summ `outcome' if between==0
				
					local c_11_`outcome' : di%12.3f `r(mean)'
					local sd_11_`outcome' : di%12.3f `r(sd)'
					local n_11_`outcome' = `r(N)'
					
			* All community members
				
				summ `outcome' if infrastructure!=.
				
					local c_12_`outcome' : di%12.3f `r(mean)'
					local sd_12_`outcome' : di%12.3f `r(sd)'
					local n_12_`outcome' = `r(N)'


			* Treatment community members
				
				summ `outcome' if infrastructure==1
				
					local c_13_`outcome' : di%12.3f `r(mean)'
					local sd_13_`outcome' : di%12.3f `r(sd)'
					local n_13_`outcome' = `r(N)'

			* Control community members
				
				summ `outcome' if infrastructure==0
				
					local c_14_`outcome' : di%12.3f `r(mean)'
					local sd_14_`outcome' : di%12.3f `r(sd)'
					local n_14_`outcome' = `r(N)'
					
	}
				
				
						

	
	foreach outcome of local all_summstats_Tunisia_only {
		
		 local l_`outcome' : variable label `outcome'
		
	}

	
	
* Save tables

	file open Table using "Output/`title'.tex", text write replace

	file write Table  _n ///
	"\begin{tabular}{l*{13}{c}}\hline&\multicolumn{3}{c}{\textbf{All}}&\multicolumn{3}{c}{\textbf{Treatment}} &\multicolumn{3}{c}{\textbf{Partial control}} &\multicolumn{3}{c}{\textbf{Pure control}} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \cmidrule(l){8-10} \cmidrule(l){11-13} & {Mean} & {SD} & {N} & {Mean} & {SD} & {N} & {Mean} & {SD} & {N} & {Mean} & {SD} & {N} \\ \cmidrule(r){2-4}\cmidrule(l){5-7} \cmidrule(l){8-10} \cmidrule(l){11-13} & {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} & {(7)} & {(8)} & {(9)} & {(10)} & {(11)} & {(12)} \\ \midrule \multicolumn{1}{p{1.3cm}}{\textbf{Egypt}} & &  &    \\ \cmidrule(r){1-4}\cmidrule(l){5-7} \cmidrule(l){8-10} \cmidrule(l){11-13}"   _n

	foreach outcome of local all_summstats_Egypt_only {
		
	file write Table																																	_n ///
	"`l_`outcome'' & `c_1_`outcome''  & `sd_1_`outcome'' & `n_1_`outcome'' & `c_2_`outcome'' & `sd_2_`outcome'' & `n_2_`outcome'' & `c_3_`outcome'' & `sd_3_`outcome''   & `n_3_`outcome''   & `c_4_`outcome'' & `sd_4_`outcome''  & `n_4_`outcome''                                                                                        \\"  _n 
	}

	file write Table  _n ///
	"\cmidrule(r){1-4}\cmidrule(l){5-7} \cmidrule(l){8-10} \cmidrule(l){11-13} \multicolumn{1}{p{1.3cm}}{\textbf{Tunisia}} & &  &    \\ \cmidrule(r){1-4}\cmidrule(l){5-7} \cmidrule(l){8-10} \cmidrule(l){11-13} "   _n


	foreach outcome of local all_summstats_Tunisia_only {
		
		file write Table                   _n ///
	"`l_`outcome'' & `c_8_`outcome''  & `sd_8_`outcome'' & `n_8_`outcome'' & `c_9_`outcome'' & `sd_9_`outcome'' & `n_9_`outcome'' & `c_10_`outcome'' & `sd_10_`outcome''   & `n_10_`outcome''   & `c_11_`outcome'' & `sd_11_`outcome''  & `n_11_`outcome''                                                                                        \\"  _n 
	}

	file write Table					_n ///
			"\hline \end{tabular}"													_n

	file close Table


